package com.drink.yan.web.rest;

import com.drink.yan.domain.YanUserDo;
import com.drink.yan.intf.define.YanOpSourceStatusE;
import com.drink.yan.intf.entity.*;
import com.drink.yan.intf.vo.*;
import com.drink.yan.svc.service.YanActivityService;
import com.drink.yan.svc.service.YanOrderService;
import com.drink.yan.svc.service.YanTaskService;
import com.drink.yan.svc.service.YanUserService;
import com.drink.yan.web.rest.req.cmd.*;
import com.drink.yan.web.rest.req.qry.*;
import com.github.meixuesong.aggregatepersistence.Aggregate;
import com.meta.framework.common.core.controller.BaseController;
import com.meta.framework.common.core.page.TableResponseVo;
import com.meta.framework.common.utils.SecurityUtils;
import com.meta.framework.core.ResponseVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * java类简单作用描述
 *
 * @Title:
 * @Package: com.drink.yan.web.rest.app.
 * @Author: M.simple
 * @Remark: The modified content
 * @CreateDate: 2023/11/23 14:58
 * @Version: v2.0
 */
@RestController
@RequestMapping("/customer")
public class CustomerRest extends BaseController {


    @Resource
    private YanActivityService yanActivityService;

    @Resource
    private YanUserService yanUserService;

    @Resource
    private YanOrderService yanOrderService;

    @Resource
    private YanTaskService yanTaskService;

    @ApiOperation(value = "用户明细", notes = "用户明细", tags = {"学生小程序"})
    @GetMapping("/detail/{userId}")
    public ResponseVo<UserVo> detail(@PathVariable Long userId){

        UserVo yanUserDo = yanUserService.getYanUserVo(userId);
        return ResponseVo.success(yanUserDo);
    }

    @ApiOperation(value = "获取客户的体验课", notes = "获取客户的体验课", tags = {"学生小程序"})
    @GetMapping("/listCourse")
    public TableResponseVo<List<SkuVo>> listCourse(PageMyDataQry qry){

        startPage();
        List<SkuVo> list = yanOrderService.listCourse(qry);
        return getResponseVoTable(list);
    }

    @ApiOperation(value = "获取客户已购买的资料", notes = "获取客户已购买的资料", tags = {"学生小程序"})
    @GetMapping("/listStudyFile")
    public TableResponseVo<List<SkuVo>> listStudyFile(PageMyDataQry qry){

        CustomerVo customerVo = new CustomerVo();
        Long userId = SecurityUtils.getUserId();
        startPage();
        List<SkuVo> list = yanOrderService.listStudyFile(qry);
        return getResponseVoTable(list);
    }

    @ApiOperation(value = "获取客户参与的活动", notes = "获取客户参与的活动", tags = {"学生小程序"})
    @GetMapping("/listActivity")
    public TableResponseVo<List<ActivityVo>> listActivity(PageMyActivityQry qry){

        if(Objects.isNull(qry.getCustomerUid())){
            qry.setCustomerUid(SecurityUtils.getUserId());
        }
        startPage();
        List<ActivityVo> list = yanActivityService.listActivityByUser(qry);
        return getResponseVoTable(list);
    }

    @ApiOperation(value = "我参与的活动", notes = "我参与的活动", tags = {"PC"})
    @GetMapping("/listUserActivity")
    public TableResponseVo<List<ActivityUserVo>> listUserActivity(PageMyActivityQry qry){

        if(Objects.isNull(qry.getCustomerUid())){
            qry.setCustomerUid(SecurityUtils.getUserId());
        }
        startPage();
        List<ActivityUserVo> list = yanActivityService.listUserActivity(qry);
        return getResponseVoTable(list);
    }

    @ApiOperation(value = "保存学生资料", notes = "保存学生资料", tags = {"学生小程序"})
    @PostMapping("/saveStudentInfo")
    public ResponseVo<YanUserDo> saveStudentInfo(@RequestBody AddStudentInfoCmd cmd){

        YanUserDo customerVo = yanUserService.saveStudentInfo(cmd);

        return ResponseVo.success(customerVo);
    }

    @ApiOperation(value = "申请成为代理", notes = "申请成为代理", tags = {"学生小程序"})
    @PostMapping("/applyAgency")
    public ResponseVo<YanUserDo> applyAgencyInfo(@RequestBody ApplyAgencyInfoCmd cmd){

        YanUserDo customerVo = yanUserService.applyAgency(cmd);

        return ResponseVo.success(customerVo);
    }

    @ApiOperation(value = "代理列表", notes = "代理列表", tags = {"PC"})
    @GetMapping("/agency/page")
    public TableResponseVo<List<UserAgencyVo>> pageAnency(PageAgencyQry qry){

        startPage();
        List<UserAgencyVo> list = yanUserService.listAgency(qry);

        return getResponseVoTable(list);
    }

    @ApiOperation(value = "辅导员列表", notes = "辅导员列表", tags = {"PC"})
    @GetMapping("/counselor/page")
    public TableResponseVo<List<UserCounselorVo>> pageCounselor(PageCounselorQry qry){

        startPage();
        List<UserCounselorVo> list = yanUserService.listCounselor(qry);

        return getResponseVoTable(list);
    }

    @ApiOperation(value = "学生列表", notes = "学生列表", tags = {"PC"})
    @GetMapping("/student/page")
    public TableResponseVo<List<StudentVo>> pageStudent(PageStudentQry qry){

        startPage();
        List<StudentVo> list = yanUserService.listStudent(qry);

        return getResponseVoTable(list);
    }

    @ApiOperation(value = "代理申请审核", notes = "代理申请审核", tags = {"PC"})
    @PostMapping("/agency/check")
    public ResponseVo<YanUserDo> authAnency(@RequestBody AuthAgencyCmd cmd){

        YanUserDo yanUserDo = yanUserService.authAnency(cmd);

        return ResponseVo.success(yanUserDo);
    }


    @ApiOperation(value = "申请成为学姐", notes = "申请成为学姐", tags = {"学生小程序"})
    @PostMapping("/applySenior")
    public ResponseVo<YanUserDo> applySeniorInfo(@RequestBody ApplySeniorInfoCmd cmd){

        YanUserDo customerVo = yanUserService.applySenior(cmd);

        return ResponseVo.success(customerVo);
    }

    @ApiOperation(value = "保存沟通记录", notes = "保存沟通记录", tags = {"PC"})
    @PostMapping("/commuLog/save")
    public ResponseVo<YanUserCommuLog> saveCommuLog(@RequestBody YanUserCommuLog cmd){

        YanUserCommuLog yanUserCommuLog = yanUserService.saveCommuLog(cmd);

        return ResponseVo.success(yanUserCommuLog);
    }

    @ApiOperation(value = "我的沟通记录", notes = "我的沟通记录", tags = {"PC"})
    @GetMapping("/commuLog/page")
    public TableResponseVo<List<UserCommuLogVo>> pageCommuLog(PageCommuLogQry qry){

        startPage();
        List<UserCommuLogVo> list = yanUserService.listCommuLog(qry);

        return getResponseVoTable(list);
    }

    @ApiOperation(value = "申请成为辅导员", notes = "申请成为辅导员", tags = {"学生小程序"})
    @PostMapping("/applyCounselor")
    public ResponseVo<YanUserDo> applyCounselor(@RequestBody ApplyCounselorInfoCmd cmd){

        YanUserDo customerVo = yanUserService.applyCounselor(cmd);

        return ResponseVo.success(customerVo);
    }

    @ApiOperation(value = "保存基础数据详情", notes = "保存基础数据详情", tags = {"PC"})
    @PostMapping("/detail/save")
    public ResponseVo<YanUserDo> saveUserDetail(@RequestBody YanUserDetail cmd){

        YanUserDo customerVo = yanUserService.saveUserDetail(cmd);

        return ResponseVo.success(customerVo);
    }

    @ApiOperation(value = "学姐列表", notes = "学姐列表", tags = {"PC"})
    @GetMapping("/senior/page")
    public TableResponseVo<List<UserSeniorVo>> pageSenior(PageSeniorQry qry){

        startPage();
        List<UserSeniorVo> list = yanUserService.listSenior(qry);

        return getResponseVoTable(list);
    }

    @ApiOperation(value = "我的任务", notes = "我的任务", tags = {"学生小程序"})
    @GetMapping("/task/page")
    public TableResponseVo<List<YanTaskDealVo>> pageTask(PageTaskQry qry){

        startPage();
        List<YanTaskDealVo> list = yanTaskService.listMyDealTask(qry);

        return getResponseVoTable(list);
    }

    @ApiOperation(value = "任务总面板", notes = "任务总面板", tags = {"学生小程序"})
    @GetMapping("/task/summary")
    public ResponseVo<CustomerTaskSummaryVo> customerTaskSummary(PageTaskQry qry){
        CustomerTaskSummaryVo vo = yanTaskService.customerTaskSummary(qry);

        return ResponseVo.success(vo);
    }

    @ApiOperation(value = "可接任务", notes = "可接任务", tags = {"学生小程序"})
    @GetMapping("/need/receive/page")
    public TableResponseVo<List<YanTask>> listNeedReceiveTask(PageTaskQry qry){

        startPage();
        List<YanTask> list = yanTaskService.listNeedReceiveTask(qry);

        return getResponseVoTable(list);
    }

    @ApiOperation(value = "近期活动推广", notes = "近期活动推广", tags = {"学生小程序"})
    @GetMapping("/task/now")
    public TableResponseVo<List<ActivityVo>> listNowActivity(PageActivityQry qry){

        startPage();
        List<ActivityVo> list = yanActivityService.listNowActivity(qry);

        return getResponseVoTable(list);
    }

    @ApiOperation(value = "往期活动推广", notes = "往期活动推广", tags = {"学生小程序"})
    @GetMapping("/task/share")
    public TableResponseVo<List<ActivityVo>> listShareActivity(PageActivityQry qry){

        startPage();
        List<ActivityVo> list = yanActivityService.listShareActivity(qry);
        return getResponseVoTable(list);

    }

    @ApiOperation(value = "学姐申请审核", notes = "学姐申请审核", tags = {"PC"})
    @PostMapping("/senior/check")
    public ResponseVo<YanUserDo> authSenior(@RequestBody AuthAgencyCmd cmd){

        YanUserDo yanUserDo = yanUserService.authSenior(cmd);

        return ResponseVo.success(yanUserDo);
    }

    @ApiOperation(value = "设为我的报考专业", notes = "设为我的报考专业", tags = {"学生小程序"})
    @PostMapping("/setMySpecial")
    public ResponseVo<YanUserDo> setMySpecial(@RequestBody SetMySpecialCmd cmd){

        YanUserDo customerVo = yanUserService.setMySpecial(cmd);

        return ResponseVo.success(customerVo);
    }

    @ApiOperation(value = "人员绑定", notes = "人员绑定", tags = {"学生小程序"})
    @PostMapping("/userBind")
    public ResponseVo<YanUserBind> userBind(@RequestBody YanUserBind cmd){

        YanUserBind yanUserBind = yanUserService.userBind(cmd, YanOpSourceStatusE.student_mini.getCode());

        return ResponseVo.success(yanUserBind);
    }

    @ApiOperation(value = "保存任务", notes = "保存任务", tags = {"学生小程序"})
    @PostMapping("/task/save")
    public ResponseVo<YanTaskDeal> save(@RequestBody SaveCustomerTaskCmd cmd){
        YanTaskDeal yanTask = yanTaskService.saveCustomerTask(cmd);

        return ResponseVo.success(yanTask);
    }

    @ApiOperation(value = "获取咨询老师", notes = "获取咨询老师", tags = {"学生小程序"})
    @GetMapping("/link/teacher/{userId}")
    public ResponseVo<YanUserDo> linkTeacher(@PathVariable("userId") Long userId){
        UserVo userVo = yanUserService.linkTeacher(userId);

        return ResponseVo.success(userVo);
    }

}
